/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* detectCycle(struct ListNode* head) {
    struct ListNode* slow = head, * fast = head, * start = head, * meet;
    while (fast && fast->next)
    {
        slow = slow->next;
        fast = fast->next->next;
        if (fast == slow)
        {
            meet = fast;
            break;
        }
    }
    if (fast == NULL || fast->next == NULL)
        return NULL;
    while (start != meet)
    {
        start = start->next;
        meet = meet->next;
    }
    return start;
}